package com.gtq.uhome.service.serviceImpl;

import com.gtq.uhome.mapper.OrderMapper;
import com.gtq.uhome.mapper.UserOrderRelationMapper;
import com.gtq.uhome.service.OrderQuantityService;
import com.gtq.uhome.vo.OrderCountVo;
import com.gtq.uhome.vo.OrderQuantityVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 用户前端_个人中心
 */
@Service("orderQuantityService")
@Transactional
public class OrderQuantityServiceImpl implements OrderQuantityService {

    @Resource
    private UserOrderRelationMapper userOrderRelationMapper;


    /**
     * 查询所有类型订单数量
     *
     * @param orderQuantityVo
     * @return
     */
    @Override
    public OrderCountVo findAllOrderCount(OrderQuantityVo orderQuantityVo) {
        OrderQuantityVo order = userOrderRelationMapper.findOrderUserName(orderQuantityVo);
        //获取用户名及手机号
        OrderCountVo vo = new OrderCountVo();
        vo.setUserName(order.getUserName());
        vo.setUserPhoneNumber(order.getUserPhoneNumber());
        //获取待配送订单数量
        orderQuantityVo.setOrderStatus("待取货");
        Integer toBeDeliveredCount = userOrderRelationMapper.findOrderCount(orderQuantityVo);
        vo.setToBeDelivered(Objects.isNull(toBeDeliveredCount) ? 0 : toBeDeliveredCount);
        //获取配送中订单数量
        orderQuantityVo.setOrderStatus("配送中");
        Integer deliveryInProgressCount = userOrderRelationMapper.findOrderCount(orderQuantityVo);
        vo.setDeliveryInProgress(Objects.isNull(deliveryInProgressCount) ? 0 : toBeDeliveredCount);
        //获取配送失败订单数量
        orderQuantityVo.setOrderStatus("签收成功");
        Integer signInSuccessfullyCount = userOrderRelationMapper.findOrderCount(orderQuantityVo);
        vo.setSignInSuccessfully(Objects.isNull(signInSuccessfullyCount) ? 0 : toBeDeliveredCount);
        //获取配送成功订单数量
        orderQuantityVo.setOrderStatus("签收失败");
        Integer failedToSignInCount = userOrderRelationMapper.findOrderCount(orderQuantityVo);
        vo.setFailedToSignIn(Objects.isNull(failedToSignInCount) ? 0 : toBeDeliveredCount);
        return vo;
    }
}
